package com.hk.core.service.elasticsearch.reactive;

import co.elastic.clients.elasticsearch.core.search.FieldSuggester;
import com.hk.commons.query.Order;
import com.hk.commons.query.page.QueryPage;
import com.hk.core.elasticsearch.query.Condition;
import com.hk.core.service.reactive.ReactiveBaseService;
import org.springframework.data.domain.Persistable;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * @author Kevin
 * @date 2022/7/23 17:30
 */
public interface ReactiveElasticService<T extends Persistable<ID>, ID extends Serializable>
        extends ReactiveBaseService<T, ID> {
    
    default Mono<Void> bulkUpdate(T entity) {
        return bulkUpdate(Collections.singleton(entity));
    }

    Mono<Void> bulkUpdate(Collection<T> entities);

    /**
     * 分页查询
     *
     * @param conditions 查询条件
     * @param pageIndex  分页参数，从第几页开始
     * @param pageSize   分页参数，查询多少条记录
     * @param orders     查询排序
     * @return {@link QueryPage}
     */
    Mono<QueryPage<T>> queryForPage(List<Condition> conditions, int pageIndex, int pageSize, Order... orders);

    /**
     * 查询
     *
     * @param conditions 查询条件
     * @param orders     查询排序
     * @return {@link List}
     */
    Flux<T> findAll(List<Condition> conditions, Order... orders);

    /**
     * 建议词查询
     *
     * @param suggester suggester
     */
    Flux<String> suggest(FieldSuggester suggester);
}
